#!/usr/bin/ruby

RUN="./bin/sequor"
RATE=0.1
BEAM=10
ITER=10
MINCOUNT=50
TEMPLATE1="data/all.features"
TEMPLATE2="data/mlcomp2.features"

cmd = ARGV.shift or raise "Missing command"
case cmd
  when 'setHyperparameter'
    hyperparameter = ARGV.shift
    system "echo '#{hyperparameter}' > hyperparameter" or raise "Failed"
  when 'learn' then
    inPath = ARGV.shift or raise "Missing argument (input file)"
    # do not extract word features if dataset contains more than 5 columns
    template = if File.open(inPath).readline.split.length > 5 then TEMPLATE1 else TEMPLATE2 end
    system "#{RUN} train --rate=#{RATE} --beam=#{BEAM} --iter=#{ITER} --min-count=#{MINCOUNT} #{template} #{inPath} model" or raise "Failed"
    
  when 'predict' then
    inPath = ARGV.shift or raise "Missing argument (input file)"
    outPath = ARGV.shift or raise "Missing argument (output file)"
    system "cat #{inPath} | #{RUN} predict model > #{outPath}" or raise "Failed"
end

